package com.bdqn.shequ.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bdqn.shequ.common.utils.PageUtils;
import com.bdqn.shequ.common.utils.Query;
import com.bdqn.shequ.modules.sys.dao.TcMemberDao;
import com.bdqn.shequ.modules.sys.entity.TcMemberEntity;
import com.bdqn.shequ.modules.sys.service.TcMemberService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("tcMemberService")
public class TcMemberServiceImpl extends ServiceImpl<TcMemberDao, TcMemberEntity> implements TcMemberService {

    @Override
    public boolean updateStatus(Long memberId, String statu1,String statu2) {
        TcMemberEntity tm=new TcMemberEntity();
        tm.setMemberType(statu2);
        tm.setMemberStatus(statu1);
        return this.update(tm,new QueryWrapper<TcMemberEntity>().eq("ID",memberId));
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TcMemberEntity> page = null;
        if(params.containsKey("typeNo") && !params.get("typeNo").equals(null)&& !params.get("typeNo").equals("")){
            page = this.page(
                    new Query<TcMemberEntity>().getPage(params),
                    new QueryWrapper<TcMemberEntity>().eq("MEMBER_TYPE",params.get("typeNo")).like("REAL_NAME",params.get("membername")).orderByDesc("ID")
            );
        }else{
            if( params.get("typeNo") == null ||params.get("membername").equals("")){
                page = this.page(
                        new Query<TcMemberEntity>().getPage(params),
                        new QueryWrapper<TcMemberEntity>().orderByDesc("ID")
                );
            }else{
                page = this.page(
                        new Query<TcMemberEntity>().getPage(params),
                        new QueryWrapper<TcMemberEntity>().like("REAL_NAME",params.get("membername")).orderByDesc("ID")
                );
            }
        }



        return new PageUtils(page);
    }

    @Override
    public List<TcMemberEntity> allList() {
        return this.baseMapper.allList();
    }
}
